{% extends "base.html" %}
{% import "_my_wtf_macros.html" as my_wtf_macros %}

{% block title %}万屏时代OPC--新增用户{% endblock %}

{% block panel_heading %}万屏时代OPC--新增用户{% endblock %}

{% block panel_body %}
    <form id="add-user-form" action="{{ url_for('op_bp.add_user') }}" method="post" class="form" role="form">

        <div class="well well-sm">用户信息</div>
        {{ my_wtf_macros.form_field(form.type, div_col=4, label_col=4, field_col=7) }}
        {{ my_wtf_macros.form_field(form.level, div_col=4, label_col=4, field_col=7) }}
        {{ my_wtf_macros.form_field(form.mobile, div_col=4, label_col=4, field_col=7) }}
        {{ my_wtf_macros.form_field(form.nickname, div_col=4, label_col=4, field_col=7) }}
        {{ my_wtf_macros.form_field(form.gender, div_col=4, label_col=4, field_col=7) }}
        {{ my_wtf_macros.form_field(form.prov, div_col=4, label_col=4, field_col=7) }}
        {{ my_wtf_macros.form_field(form.city, div_col=4, label_col=4, field_col=7) }}
        {{ my_wtf_macros.form_field(form.addr, div_col=4, label_col=4, field_col=7) }}
        {{ my_wtf_macros.form_field(form.com, div_col=4, label_col=4, field_col=7) }}
        {{ my_wtf_macros.form_field(form.pos, div_col=4, label_col=4, field_col=7) }}
        {{ my_wtf_macros.form_field(form.active, div_col=4, label_col=4, field_col=7) }}
        {{ my_wtf_macros.form_field(form.is_virt, div_col=4, label_col=4, field_col=7) }}
        {{ my_wtf_macros.form_field(form.status, div_col=4, label_col=4, field_col=7) }}
        {{ my_wtf_macros.form_field(form.remark, div_col=4, label_col=4, field_col=7) }}
        <div class="clearfix visible-xs-block visible-sm-block visible-md-block visible-lg-block"></div>
        {{ my_wtf_macros.form_field(form.next_outbound, div_col=2, label_col=4, field_col=7) }}
        {{ my_wtf_macros.form_field(form.publish_demand, div_col=2, label_col=4, field_col=7) }}
        <div class="clearfix visible-xs-block visible-sm-block visible-md-block visible-lg-block"></div>

        <!--下次回访-->
        <div id="next_outbound_info">
            <div class="well well-sm">设置回访</div>
            {{ my_wtf_macros.form_field(form.next_outbound_schedule_time, div_col=4, label_col=4, field_col=7) }}
            {{ my_wtf_macros.form_field(form.next_outbound_call_reason, div_col=4, label_col=4, field_col=7) }}
            <div class="clearfix visible-xs-block visible-sm-block visible-md-block visible-lg-block"></div>
        </div>

        <!--发布项目-->
        <div id="demand_info">
            <div class="well well-sm">项目信息</div>
            {{ my_wtf_macros.form_field(demand_form.cate, div_col=4, label_col=4, field_col=7) }}
            {{ my_wtf_macros.form_field(demand_form.malf, div_col=4, label_col=4, field_col=7) }}
            <div class="clearfix visible-xs-block visible-sm-block visible-md-block visible-lg-block"></div>
            {{ my_wtf_macros.form_field(demand_form.demand_type, div_col=4, label_col=4, field_col=7) }}
            {{ my_wtf_macros.form_field(demand_form.surr, div_col=4, label_col=4, field_col=7) }}
            {{ my_wtf_macros.form_field(demand_form.color, div_col=4, label_col=4, field_col=7) }}
            {{ my_wtf_macros.form_field(demand_form.span, div_col=4, label_col=4, field_col=7) }}
            {{ my_wtf_macros.form_field(demand_form.size, div_col=4, label_col=4, field_col=7) }}
            {{ my_wtf_macros.form_field(demand_form.budget, div_col=4, label_col=4, field_col=7) }}
            {{ my_wtf_macros.form_field(demand_form.demand_status, div_col=4, label_col=4, field_col=7) }}
            {{ my_wtf_macros.form_field(demand_form.tag, div_col=4, label_col=4, field_col=7) }}
            {{ my_wtf_macros.form_field(demand_form.source, div_col=4, label_col=4, field_col=7) }}
            {{ my_wtf_macros.form_field(demand_form.demand_remark, div_col=4, label_col=4, field_col=7) }}
            {{ my_wtf_macros.form_field(demand_form.admin_remark, div_col=4, label_col=4, field_col=7) }}
            <div class="clearfix visible-xs-block visible-sm-block visible-md-block visible-lg-block"></div>
        </div>

        <div class="pull-right">
            <button type="submit" class="btn btn-success"
                    id="add-user-btn">
                新增
            </button>
        </div>

    </form>

{% endblock %}


{% block scripts %}
{{ super() }}

<script>
    $(document).ready( function () {
        // 新增项目默认是安装. 所以先把故障分类隐藏
        $('#malf').hide();
        $('#malf').next('.select2').hide();
        $('label[for=malf]').hide();
        var has_pack_val = $('#has_pack').is(':checked');
        if(has_pack_val === true){
            $('#pack_info').show();
        }else {
            $('#pack_info').hide();
        }

        // 套餐联动
        $('#has_pack').change(function(){
            var val = $(this).is(':checked');
            if(val === true){
                $('#pack_info').show();
            }else {
                $('#pack_info').hide();
            }
        });

        // 发布项目联动
        var publish_demand_val = $('#publish_demand').is(':checked');
        if(publish_demand_val === true){
            $('#demand_info').show();
        }else {
            $('#demand_info').hide();
        }
        $('#publish_demand').change(function(){
            var val = $(this).is(':checked');
            if(val === true){
                $('#demand_info').show();
            }else {
                $('#demand_info').hide();
            }
        });

        // 设置回访联动
        var next_outbound_val = $('#next_outbound').is(':checked');
        if(next_outbound_val === true){
            $('#next_outbound_info').show();
        }else {
            $('#next_outbound_info').hide();
        }
        $('#next_outbound').change(function(){
            var val = $(this).is(':checked');
            if(val === true){
                $('#next_outbound_info').show();
            }else {
                $('#next_outbound_info').hide();
            }
        });

        // 省份与城市联动
        function get_city_choices(){
            var prov_name = $("#prov").val();
            if(prov_name != -1) {
                $.ajax({
                    url: "{{ url_for('op_bp.ajax_get_cities') }}" + "?prov_name=" + prov_name,
                    cache: true
                }).done(function (data) {
                    $("#city").empty();
                    for (var i = 0; i < data["choices"].length; i++) {
                        var id = data["choices"][i]["id"];
                        var name = data["choices"][i]["name"];
                        $("#city").append(
                            "<option value='" + id + "'>" + name + "</option>"
                        );
                    }
                }).fail(function () {
                    alert("获取城市列表失败，请联系系统管理员!")
                });
            }
        }
        get_city_choices();
        $("#prov").change(function (){
            get_city_choices();
        });

        $('#cate').change(function(){
            var val = $(this).val();
            if(val == '2'){
                $('#malf').show();
                $('#malf').next('.select2').show();
                $('label[for=malf]').show();
            }else{
                $('#malf').hide();
                $('#malf').next('.select2').hide();
                $('label[for=malf]').hide();
            }

        });
    });
</script>

{% endblock %}
